//
//  DateViewController.m
//  体育商城
//
//  Created by  on 2022/9/24.
//

#import "DateViewController.h"

@interface DateViewController ()<UIPickerViewDelegate,UIPickerViewDataSource>
@property (strong, nonatomic) IBOutlet UIPickerView *pickView;
@property (nonatomic, strong) NSArray *array;

@end

@implementation DateViewController
- (void)viewDidLoad {
    [super viewDidLoad];
    [self initUI];
}
- (void)initUI{
    self.array = @[@"10后",@"00后",@"90后",@"80后",@"70后",@"60后",@"50后",@"40后",@"30后",@"20后"];
    [self.pickView selectRow:0 inComponent:0 animated:NO];
   CGRect bounds = CGRectMake(0, 0, SCREEN_WIDTH, self.pickView.frame.size.height);
    UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(20, 20)];
   CAShapeLayer *layer = [CAShapeLayer layer];
    layer.frame = bounds;
    layer.path = path.CGPath;
    self.pickView.layer.mask = layer;
}
- (IBAction)actionForBtn:(UIButton *)sender {
    [self dismissViewControllerAnimated:NO completion:nil];
}
#pragma mark - UIPickerViewDataSource
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
    return 1;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
    return self.array.count;
}
#pragma mark - UIPickerViewDelegate
- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component{
    return 100;
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
    if (self.block) {
        self.block(row, self.array[row]);
    }
}
- (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component{
    return 44;
}
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view{
    UILabel *lbl = [UILabel new];
    lbl.textAlignment = NSTextAlignmentCenter;
    lbl.textHexColor = @"#1A1A1A";
    lbl.font = [UIFont systemFontOfSize:16];
    lbl.text = LS(self.array[row]);
    return lbl;
}

@end
